import CryptoJS from './crypto-js.js';
function secret_ori(string, operation) {
	var code = 'lunaqi3195';
	code = CryptoJS.MD5(code).toString();
	var iv = CryptoJS.enc.Utf8.parse(code.substring(0,16));
	var key = CryptoJS.enc.Utf8.parse(code.substring(16));
	if(operation){
		// console.log(string, operation)
		string = CryptoJS.enc.Base64.parse(string).toString(CryptoJS.enc.Utf8)
		return CryptoJS.AES.decrypt(string,key,{iv:iv,padding:CryptoJS.pad.Pkcs7}).toString();
	}
	return CryptoJS.AES.encrypt(string, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7}).toString();
}

function secret(string, operation) {
	let code = 'lunaqi3195';
	code = CryptoJS.MD5(code).toString();
	let iv = CryptoJS.enc.Utf8.parse(code.substring(0,16));
	let key = CryptoJS.enc.Utf8.parse(code.substring(16));

	if(operation){
		// console.log(string, operation)
		string = CryptoJS.enc.Base64.parse(string).toString(CryptoJS.enc.Utf8)
		
		let decrypted = CryptoJS.AES.decrypt(string,key, {
			iv:iv,
			padding: CryptoJS.pad.Pkcs7
		}).toString(CryptoJS.enc.Utf8);
		return decrypted;	
	}
	return CryptoJS.AES.encrypt(string, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7}).toString();
}


/*aes解密*/
	function decryptAES(word,keyStr) {
		let a = CryptoJS.enc.Base64.parse(word).toString(CryptoJS.enc.Utf8) // Base64转码 如果不用就注释把下面的a改成word
		keyStr = keyStr ? keyStr : 'Ftjiw9LlPgjd1oaJ';
		let key = CryptoJS.enc.Utf8.parse(keyStr);
		let decrypted = CryptoJS.AES.decrypt(a,key, {
			mode: CryptoJS.mode.ECB,
			padding: CryptoJS.pad.Pkcs7
		});
		return CryptoJS.enc.Utf8.stringify(decrypted).toString();
}




module.exports = {    
	secret:secret
}